//
//  HJCComposeImageViewCell.swift
//  新浪微博Swift
//
//  Created by 郝俊聪 on 15/5/22.
//  Copyright (c) 2015年 heima. All rights reserved.
//

import UIKit

protocol HJCComposeImageViewCellDelegate : NSObjectProtocol{
    func composeImageViewCellClickImageBtn(cell:HJCComposeImageViewCell)
    func composeImageViewCellClickCloseBtn(cell:HJCComposeImageViewCell)
}

class HJCComposeImageViewCell: UICollectionViewCell {
    @IBOutlet weak var imageBtn: UIButton!
    
    //定义一个代理属性
    weak var delegate : HJCComposeImageViewCellDelegate?
    
    var image : UIImage?{
        didSet{
        
            if image == nil{
               
               imageBtn.setImage(nil, forState: UIControlState.Normal)
               imageBtn.setBackgroundImage(UIImage(named: "compose_pic_add"), forState: UIControlState.Normal)
                
            }else{
                
               imageBtn.setImage(image, forState: UIControlState.Normal)
               imageBtn.setBackgroundImage(nil, forState: UIControlState.Normal)
            }
        }
    
    }
    
    @IBAction func clickImageBtn(sender: UIButton) {
        //通知控制器去获取图片
        delegate?.composeImageViewCellClickImageBtn(self)
        
    }
    @IBAction func clickCloseBtn(sender: UIButton) {
        //通知控制删除图片
        delegate?.composeImageViewCellClickCloseBtn(self)
    }
    
}
